/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ParameterFrame.java
 *
 * Created on 24.9.2009, 15:32:55
 */
package vision;

import javax.swing.JFrame;

/**
 *
 * @author Kotuc
 */
public class ParameterFrame extends javax.swing.JFrame {

    private final Parameter parameter;

    /** Creates new form ParameterFrame */
    public ParameterFrame(Parameter param) {
        super(param.getName());
        this.parameter = param;
        initComponents();
        jTextField1.setText("" + param.getValue());
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTextField1.setColumns(20);
        jTextField1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField1.setText("jTextField1");
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });
        jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextField1FocusLost(evt);
            }
        });
        getContentPane().add(jTextField1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        try {
            double newVal = Double.valueOf(jTextField1.getText());
            this.parameter.setValue(newVal);
        } catch (NumberFormatException numberFormatException) {
            jTextField1.setText(this.parameter.getValue() + "ERR");
        }

    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField1FocusLost
        try {
            double newVal = Double.valueOf(jTextField1.getText());
            this.parameter.setValue(newVal);
        } catch (NumberFormatException numberFormatException) {
            jTextField1.setText(this.parameter.getValue() + "ERR");
        }
    }//GEN-LAST:event_jTextField1FocusLost

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
//                new ParameterFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
